{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "5a2ce12f",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    "* 关于麦克风包安装  \n",
    "* 优化ASR(自动语音识别)机器人  \n",
    "* 连接图灵机器人(不用自己的字典)  \n",
    "* 语音合成\n",
    "# 关于麦克风包安装  \n",
    "* 安装 speech_recognition  \n",
    "* pip install SpeechRecognition  \n",
    "* 安装 PyAudio\n",
    "* pip install pipwin\n",
    "* pipwin install PyAudio\n",
    "# 优化ASR(自动语音识别)机器人"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "97f74f32",
   "metadata": {},
   "outputs": [],
   "source": [
    "API_KEY = 'qExxsEzTBcaQxsDOLi1kWhXd'\n",
    "SECRET_KEY = 'kGDdYmGyjy0iwngA8E6imIY26SEtGH2B'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "3cf62812",
   "metadata": {},
   "outputs": [],
   "source": [
    "from bdasr import fetch_token,asr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1c4f5d24",
   "metadata": {},
   "outputs": [],
   "source": [
    "CR_token = fetch_token(API_KEY,SECRET_KEY)\n",
    "CR_token"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3024bada",
   "metadata": {},
   "outputs": [],
   "source": [
    "import speech_recognition\n",
    "r = speech_recognition.Recognizer()\n",
    "with speech_recognition.Microphone() as source:\n",
    "    audio = r.listen(source)\n",
    "# 将数据保存到wav文件中\n",
    "with open(\"1.wav\", \"wb\") as f: \n",
    "    f.write(audio.get_wav_data(convert_rate=16000))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "235431aa",
   "metadata": {},
   "outputs": [],
   "source": [
    "asr(CR_token,'1.wav')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
